home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 2 / Macwelt DVD 2.cdr / System / System-Utilities / macosx / Keep Sound Awake 1.2.dmg / KeepSoundAwake 1.2 / source / KSAPrefs / MFKSAPreferencePane.m < prev   
Encoding:
Text File  |  2002-04-07  |  3.1 KB  |  86 lines

  1. /*
  2.     Copyright (c) 2002, Jonathan Feinberg
  3.     All rights reserved.
  4.     
  5.     Redistribution and use in source and binary forms, with or without
  6.     modification, are permitted provided that the following conditions are
  7.     met:
  8.     
  9.     *    Redistributions of source code must retain the above copyright
  10.         notice, this list of conditions and the following disclaimer.
  11.     *    Redistributions in binary form must reproduce the above copyright
  12.         notice, this list of conditions and the following disclaimer in the
  13.         documentation and/or other materials provided with the distribution.
  14.     *    The name of the author may not be used to endorse or promote
  15.         products derived from this software without specific prior written
  16.         permission.
  17.     
  18.     
  19.     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20.     IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  21.     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  22.     PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  23.     OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24.     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25.     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26.     PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27.     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28.     NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29.     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.  
  31.     $Id: MFKSAPreferencePane.m,v 1.2 2002/04/07 15:41:00 jdf Exp $
  32.  
  33. */
  34. #import <CoreFoundation/CoreFoundation.h>
  35. #import "MFKSAPreferencePane.h"
  36.  
  37. #import "KSAPrefConstants.h"
  38.  
  39. @implementation MFKSAPreferencePane
  40.  
  41. - (void)mainViewDidLoad
  42. {
  43.     NSString *period;
  44.     NSString *chargerAwareness;
  45.  
  46.     CFPreferencesAddSuitePreferencesToApp(kCFPreferencesCurrentApplication, (CFStringRef)suiteID);
  47.  
  48.     period = (NSString *)CFPreferencesCopyAppValue((CFStringRef)MFKSASeconds, (CFStringRef)suiteID);
  49.     [secondsText setStringValue:(period ? period : @"20")];
  50.  
  51.     chargerAwareness = (NSString *)CFPreferencesCopyAppValue((CFStringRef)MFKSAWatchCharger, (CFStringRef)suiteID);
  52.     [allowSleepCheckbox setState:( chargerAwareness ? [chargerAwareness intValue] : YES )];
  53. }
  54.  
  55. - (void)updatePrefs
  56. {
  57.     NSString * chargerAwareness = [NSString stringWithFormat:@"%d", [allowSleepCheckbox state]];
  58.     NSString * period = [secondsText stringValue];
  59.     CFPreferencesSetAppValue((CFStringRef)MFKSAWatchCharger, chargerAwareness, (CFStringRef)suiteID);
  60.     CFPreferencesSetAppValue((CFStringRef)MFKSASeconds, period, (CFStringRef)suiteID);
  61.     CFPreferencesAppSynchronize((CFStringRef)suiteID);
  62.     CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(), 
  63.                                          (CFStringRef)MFKSAPrefsChangedNotification,
  64.                                          (CFStringRef)suiteID, 
  65.                                          NULL /* no dictionary */, 
  66.                                          TRUE);
  67. }
  68.  
  69. - (IBAction)changeAllowSleep:(id)sender
  70. {
  71.     [self updatePrefs];
  72. }
  73.  
  74. - (IBAction)changeSeconds:(id)sender
  75. {
  76.     [self updatePrefs];
  77. }
  78.  
  79. - (void)willUnselect
  80. {
  81.     [self updatePrefs];
  82.     [super willUnselect];
  83. }
  84.  
  85. @end
  86.